#ifndef MGUI_FONT_H
#define MGUI_FONT_H

#include "MGUI_Types.h"

namespace Myway {

	struct MGUI_ENTRY MGUI_Glyph {
		float u0, v0;
		float u1, v1;

		float width;
		float height;

		float bearingX;
		float bearingY;

		float advance;

		Texture * texture;

		MGUI_Glyph()
		{
			u0 = v0 = 0;
			u1 = v1 = 0;

			width = height = 0;
			bearingX = bearingY = 0;

			advance = 0;

			texture = NULL;
		}
	};



	class MGUI_ENTRY MGUI_Font
	{
	public:
		MGUI_Font(const TString128 & name, void * _face, int _charSize);
		~MGUI_Font();

		const TString128 & Name() { return mName; }
		float Height() { return mHeight; }

		const MGUI_Glyph * GetGlyph(MGUI_Char _char);

	protected:
		bool _LoadGlyph(MGUI_Glyph & _glyph, MGUI_Char _char);

		void _IncTexture(int w, int h);

	protected:
		TString128 mName;
		void * mFace;
		int mCharSize;

		Array<TexturePtr> mTextures;
		HashMap<MGUI_Char, MGUI_Glyph> mGlyphs;

		float mAscender;
		float mDescender;
		float mHeight;

		Texture * _texture;
		int _height;
		int _x, _y;
	};



	class MGUI_ENTRY MGUI_FontManager
	{
		DECLARE_SINGLETON(MGUI_FontManager);

	public:
		MGUI_FontManager();
		~MGUI_FontManager();

		void Load(const TString128 & _source);

		MGUI_Font * GetFont(const TString128 & _name);
		MGUI_Font * GetDefaultFont();

	protected:
		void * _loadFace(const TString128 & _face);

	protected:
		Array<MGUI_Font*> mFonts;

		Map<TString128, void *> mFaceMap;
		Array<DataStreamPtr> mFaceData;
	};

}

#endif